package com.hnkywl.sts.action.wlgl;

import com.hnkywl.sts.entity.organ.Ysgj;
import com.hnkywl.sts.service.wlgl.ZjglService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created with IntelliJ IDEA.
 * User: lenovo
 * Date: 13-6-4
 * Time: 上午12:32
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/wlgl/zjgl")
public class ZjglAction extends SimpleActionSupport {
    private ZjglService zjglService;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    private Ysgj ysgj;
    private Long ysgjId;
    // 查询条件
    private String wlsmc;
    private Long wlsId;
    private String ysgjlx;
    private Long ysgjlxId;
    //销售配送单的查询分页显示
    @Action("zjglList")
    public void zjglList() {
        this.renderJson(this.zjglService.findZjglList(wlsmc,wlsId,ysgjlx,ysgjlxId,page, rows));
    }

    @Action("zjgl_content")
    public String zjglContent() {
        if (ysgjId != null){
            ysgj = zjglService.findYsgjDetail(ysgjId);
        }
        return SUCCESS;
    }

    /**
     * 保存载具
     */
    @Action("add_zjgl")
    public void addZjgl() {
        try {
            this.zjglService.saveZjgl(ysgj);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加载具成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 修改载具
     */
    @Action("update_zjgl")
    public void updateZjgl() {
        try {
            this.zjglService.updateZjgl(ysgj);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改载具成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("delete_zjgl")
    public void deleteZjgl() {
        try {
            this.zjglService.deleteZjgl(ysgjId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除载具成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    //================getter========setter=============


    public String getYsgjlx() {
        return ysgjlx;
    }

    public void setYsgjlx(String ysgjlx) {
        this.ysgjlx = ysgjlx;
    }

    public Long getYsgjlxId() {
        return ysgjlxId;
    }

    public void setYsgjlxId(Long ysgjlxId) {
        this.ysgjlxId = ysgjlxId;
    }

    public String getWlsmc() {
        return wlsmc;
    }

    public void setWlsmc(String wlsmc) {
        this.wlsmc = wlsmc;
    }

    public Long getWlsId() {
        return wlsId;
    }

    public void setWlsId(Long wlsId) {
        this.wlsId = wlsId;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public Ysgj getYsgj() {
        return ysgj;
    }

    public void setYsgj(Ysgj ysgj) {
        this.ysgj = ysgj;
    }

    public Long getYsgjId() {
        return ysgjId;
    }

    public void setYsgjId(Long ysgjId) {
        this.ysgjId = ysgjId;
    }

    @Autowired
    public void setZjglService(ZjglService zjglService) {
        this.zjglService = zjglService;
    }
}
